package levels;
import mainGame.PathPoint;
import util.resources.ResourceManager;


public class BubbleFishBobLevel implements ILevel{
	private int myID;
	private boolean meComplete;
	private int myFishToSave;
	private double myPathSpeed;
	private double myPathIncX;
	private double myPathIncY;
	private double myPathStartT;
	private int myNumPathPoints;
	private PathPoint[] myPath;
	
	@Override
	public void initLvl(int levelID)
    {
    	ResourceManager resource = ResourceManager.getInstance();
    	resource.addResourcesFromFile("levelData/level");
    	String[] levelData = resource.getStringArray("" + levelID);
    	this.myID = (Integer.parseInt(levelData[0]));
    	this.myFishToSave = (Integer.parseInt(levelData[1]));
    	this.myPathSpeed = (Double.parseDouble(levelData[2]));
    	this.myPathIncX = Double.parseDouble(levelData[3]);
    	this.myPathIncY = Double.parseDouble(levelData[4]);
    	this.myPathStartT = (Double.parseDouble(levelData[5]));
    	this.myNumPathPoints = Integer.parseInt(levelData[6]);
    	this.myPath = new PathPoint[myNumPathPoints];
    	this.setPath(levelData[7]);
    }
	private void setPath(String properties){
		ResourceManager resource = ResourceManager.getInstance();
    	resource.addResourcesFromFile("levelData/" + properties);
		for(int k = 0; k < myNumPathPoints; k++)
		{
			int[] data = resource.getIntegerArray("" + (k+1));
			this.setPathPoint(k, data[0], data[1]);
		}
	}
	private void setPathPoint (int idx, double x, double y)
    {
        this.myPath[idx] = new PathPoint();
        this.myPath[idx].setX((x + myPathIncX) * 0.71);
        this.myPath[idx].setY((y + myPathIncY - 10) * 0.71);
        if (idx > 0)
        {
            double dx = this.myPath[idx - 1].getX() - this.myPath[idx].getX();
            double dy = this.myPath[idx - 1].getY() - this.myPath[idx].getY();
            this.myPath[idx - 1].setDist_to_next(Math.sqrt(dx * dx + dy * dy));
        }
    }
	
	public void setID(int ID) {
		this.myID = ID;
	}
	public int getID() {
		return myID;
	}
	public void setFishToSave(int FishToSave) {
		this.myFishToSave = FishToSave;
	}
	public int getFishToSave() {
		return myFishToSave;
	}
	public void setPathSpeed(double PathSpeed) {
		this.myPathSpeed = PathSpeed;
	}
	public double getPathSpeed() {
		return myPathSpeed;
	}
	public void setPathStartT(double PathStartT) {
		this.myPathStartT = PathStartT;
	}
	public double getPathStartT() {
		return myPathStartT;
	}
	public int getNumPathPoints() {
		return myNumPathPoints;
	}
	public void setNumPathPoints(int NumPathPoints) {
		this.myNumPathPoints = NumPathPoints;
	}
	public PathPoint[] getPath() {
		return myPath;
	}
	public void setPath(PathPoint[] Path) {
		this.myPath = Path;
	}
	
	@Override
	public boolean isComplete() {
		return this.meComplete;
	}
	@Override
	public void setComplete(boolean complete) {
		this.meComplete = complete;
	}
}
